package org.example.service.serviceimpl;
import org.example.dao.Dao;
import org.example.pojo.Dept;
import org.example.service.Service;
import org.springframework.beans.factory.annotation.Autowired;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;



@org.springframework.stereotype.Service
public class DeptServiceImpl implements Service {
    @Autowired
    private Dao dao;
    @Override
    public List<Dept> findAll() {
        List<String> lines = dao.findAll();
        //2. 对原始数据进行处理 , 组装部门数据
        List<Dept> deptList = lines.stream().map(line -> {
            String[] parts = line.split(",");
            Integer id = Integer.parseInt(parts[0]);
            String name = parts[1];
            LocalDateTime updateTime = LocalDateTime.parse(parts[2], DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
            return new Dept(id, name, updateTime);
        }).toList();

        return deptList;
    }
}
